package com.shouhuobao.bhi.stamp;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.engine.Resource;
import com.collectplus.express.BaseActivity2;
import com.collectplus.express.R;
import com.collectplus.express.logic.AppLogic;
import com.collectplus.express.model.CouponBean;
import com.collectplus.express.self.SelfFormInfoActivity;
import com.shouhuobao.samecity.SameCityFormActivity;

/**
 * 邮票详情界面
 */
public class StampDetailsActivity extends BaseActivity2 implements View.OnClickListener {

    private CouponBean couponBean = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        couponBean = (CouponBean) getIntent().getSerializableExtra("stampbean");
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void findViewById() {
        setContentView(R.layout.stamp_details);
        super.findViewById();
        getAppTitle().setCommonTitle("邮票详情");
        findViewById(R.id.immediate_use_btn).setOnClickListener(this);
        if (couponBean == null) {
            return;
        }
        TextView eamples = findViewById(R.id.eamples_of_others_btn);
        if (couponBean.isTransferFlag()) {
            eamples.setText("转赠他人");
            eamples.setBackgroundResource(R.drawable.stamp_detail_btn_bg_shape);
            eamples.setTextColor(Color.parseColor("#848c97"));
            eamples.setOnClickListener(this);
        } else {
            eamples.setText("该邮票不能转赠");
            eamples.setBackgroundResource(R.drawable.stamp_detail_btn_bg_no_shape);
            eamples.setTextColor(Color.parseColor("#B1B1B1"));
            eamples.setOnClickListener(null);
        }
        AppLogic.getInstance().loadImage(couponBean.getImage(), (ImageView) findViewById(R.id.stamp_iv));
        ((TextView) findViewById(R.id.stamp_name_tv)).setText(couponBean.getName());
        ((TextView) findViewById(R.id.stamp_series_tv)).setText(couponBean.getSeries());
        if (isNotEmpty(couponBean.getExpireDate())) {
            ((TextView) findViewById(R.id.stamp_expiredate_tv)).setText("有效期至" + couponBean.getExpireDate());
        } else {
            if (isNotEmpty(couponBean.getValidStart()) && isNotEmpty(couponBean.getValidEnd())) {
                ((TextView) findViewById(R.id.stamp_expiredate_tv)).setText("有效期" + couponBean.getValidStart().substring(0, 10) + "至" + couponBean.getValidEnd().substring(0, 10));
            }
        }
        ((TextView) findViewById(R.id.stamp_use_conditions_tv)).setText("使用条件：" + couponBean.getCondition());
        ((TextView) findViewById(R.id.stamp_source_tv)).setText("邮票来源："+couponBean.getStampFrom());
        ((TextView) findViewById(R.id.stamp_acquisition_time_tv)).setText("获得时间："+couponBean.getCreateTime());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //立即使用
            case R.id.immediate_use_btn:
                if (couponBean != null && couponBean.isSameCityStamp()) {
                    startActivity(SameCityFormActivity.class);
                } else {
                    startActivity(SelfFormInfoActivity.class);
                }
                break;
            //转赠他人
            case R.id.eamples_of_others_btn:
                if (couponBean == null) {
                    return;
                }
                Intent intent = new Intent(getContext(), StampTransformActivity.class);
                intent.putExtra("stampbean", couponBean);
                startActivityForResult(intent, 101);
                break;

        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (RESULT_OK != resultCode) {
            return;
        }
        if (requestCode == 101) {
            boolean isfinish = data.getBooleanExtra("finish", false);
            if (isfinish) {
                finish();
            }
        }
    }
}
